package com.aaa.controller;

import com.aaa.entity.Class;
import com.aaa.service.ClassService;
import com.aaa.vo.Echart01;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/echarts")
public class EchartsController {
    @Autowired
    private ClassService classService;

    @GetMapping("/demo01")
    @ResponseBody
    public Echart01 demo01(){
        Echart01 echart01=new Echart01();
        List<String> x=new ArrayList<String>(); //查询数据库得到
        //拿到班级数据
        List<Class> allClass = classService.getAllClass();
        for (Class c:allClass) {
            x.add(c.getGrade());
        }

        List<Integer> y=new ArrayList<Integer>();
        //拿到各个班级对应的人数
        List<Class> counts = classService.stuCount();
        for (Class stuCount:counts) {
            y.add(stuCount.getStuCount());
        }

        echart01.setXDatas(x);
        echart01.setYDatas(y);

        return echart01;

    }
}
